<?php
  /**
   * @author EVANDRO DE OLIVEIRA.
   * @category PLUGINS.
   * @since 14/09/2010.
   * @copyright 2010.
   * @version 1.0.
   *
   * Plugin que Manipula a view antes de mandar para o browser
   *
  */
  
  class Core_Seguranca_Plugin extends Zend_Controller_Plugin_Abstract{  
	  public function preDispatch(Zend_Controller_Request_Abstract $request){
	  	//Verificação de sessão existente.
      $objAuthNamespace = new Zend_Session_Namespace('Zend_Auth');
      
      $strDsNome        = $objAuthNamespace->ds_nome;
      $strDsLogin       = $objAuthNamespace->ds_login;
      $strDsSexo        = $objAuthNamespace->ds_sexo;
      $intIdPerfil      = $objAuthNamespace->idPerfil;
      $intStFuncionario = $objAuthNamespace->st_funcionario;
      
      // Capturando a controller e a action acessada.
      $strControllerName = $request->getControllerName();
      $strActionName = $request->getActionName();
      
      if($intIdPerfil != '' && $strDsLogin != '' && ($intStFuncionario != '' && $intStFuncionario != 0)){ 
	    	$objAuthNamespace->session_initialized = true;
	    	
	    	$strTimeExpiration = Zend_Registry::getInstance()->config->default->time->expiration;
        $objModelAccess = new Application_Model_ControlAccess();
        if(!$objModelAccess->verifyTimeAction($objAuthNamespace->idFuncionario, $strTimeExpiration))
          $objAuthNamespace->session_initialized = false;
        else{
          $objModelAccess->updateAction($objAuthNamespace->idFuncionario);
        }  
	    }
	    else{
	      $objAuthNamespace->session_initialized = false;
	    } 
	  }
  }
?>